package com.shroo8.footballblog.controllers.test;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.shroo8.footballblog.bo.api.GetArticleBo;
import com.shroo8.footballblog.dto.api.ArticleDto;

@Controller
public class ViewArticleController {
	private static final Logger logger = LoggerFactory.getLogger(ViewArticleController.class);

	@Resource(name="getArticleBo", type=com.shroo8.footballblog.bo.api.GetArticleBoImpl.class)
	GetArticleBo getArticleBo;
	
	@RequestMapping(value = "/viewarticle", method = RequestMethod.GET)
	public ModelAndView updateArticle(Locale locale, Model model, @RequestParam("articleId") String articleId) {
		logger.info("Testing: Welcome to the test viewArticleController! The client locale is {}.", locale);
		
		Date date = new Date();
		DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
		
		String formattedDate = dateFormat.format(date);
		
		model.addAttribute("serverTime", formattedDate );
		
		ArticleDto articleDto = getArticleBo.getArticle(articleId);
		
		return new ModelAndView("viewArticleDojo", "articleDto", articleDto);
	}


}
